package ictbk.ttmk51.grapro.app.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class GetListFile {
	
	public static List<String> ReadSDCard(File Directory){  
		List<String> tFileList = new ArrayList<String>();
		 //It have to be matched with the directory in SDCard  
		if(Directory.isDirectory() && Directory.listFiles() != null){
			File[] files=Directory.listFiles(); 
			for(int i=0; i<files.length; i++)  
			{  
				File file = files[i];  
				/*It's assumed that all file in the path 
				 are in supported type*/
				if(file.isFile())
					tFileList.add(file.getPath());
				else
					ReadSDCard(file);
			 }  
		 }
		return tFileList;  
	}
	
	public static List<String> ReadImageFile(File folder){
		File[] imageFiles = new File[ReadSDCard(folder).size()];
		List<String> PathOfImageFile = new ArrayList<String>();
		PathOfImageFile.clear();
		for(int i = 0; i <ReadSDCard(folder).size(); i++){
			imageFiles[i] = new File(ReadSDCard(folder).get(i));
			if(CheckFile.isImageFile(imageFiles[i])){
				PathOfImageFile.add(imageFiles[i].getAbsolutePath());
			}
		}
		return PathOfImageFile;
	}
	
	public static List<String> ReadDocumentFile(File folder){
		File[] imageFiles = new File[ReadSDCard(folder).size()];
		List<String> PathOfImageFile = new ArrayList<String>();
		PathOfImageFile.clear();
		for(int i = 0; i < ReadSDCard(folder).size(); i++){
			imageFiles[i] = new File(ReadSDCard(folder).get(i));
			if(CheckFile.isDocumentFile(imageFiles[i])){
				PathOfImageFile.add(imageFiles[i].getAbsolutePath());
			}
		}
		return PathOfImageFile;
	}
	
	public static List<String> ReadApplicationFile(File folder){
		File[] imageFiles = new File[ReadSDCard(folder).size()];
		List<String> PathOfImageFile = new ArrayList<String>();
		PathOfImageFile.clear();
		for(int i = 0; i <ReadSDCard(folder).size(); i++){
			imageFiles[i] = new File(ReadSDCard(folder).get(i));
			if(CheckFile.isApplicationFile(imageFiles[i])){
				PathOfImageFile.add(imageFiles[i].getAbsolutePath());
			}
		}
		return PathOfImageFile;
	}
}
